using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWDPLAN
    {
        public DataRow Convert2WDPLAN(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWDPLAN(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WDPMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WDPWAKZ"] = " ".PadRight(1 ); 
         dwReturn["WDPKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WDPWERK"] = " ".PadRight(3 ); 
         dwReturn["WDPABT"] = " ".PadRight(3 ); 
         dwReturn["WDPDART"] = " ".PadRight(20 ); 
         dwReturn["WDPDVAR"] = " ".PadRight(2 ); 
         dwReturn["WDPDESS"] = " ".PadRight(10 ); 
         dwReturn["WDPCOLORIT"] = " ".PadRight(10 ); 
         dwReturn["WDPFARBE"] = " ".PadRight(10 ); 
         dwReturn["WDPBESCHICH"] = " ".PadRight(10 ); 
         dwReturn["WDPPROGRP"] = " ".PadRight(3 ); 
         dwReturn["WDPARTGRP"] = " ".PadRight(3 ); 
         dwReturn["WDPPLMGA"] = " ".PadRight(0 ); 
         dwReturn["WDPERFBENA"] = " ".PadRight(8 ); 
         dwReturn["WDPERFDATA"] = " ".PadRight(8 ); 
         dwReturn["WDPPLMGN"] = " ".PadRight(0 ); 
         dwReturn["WDPERFBENN"] = " ".PadRight(8 ); 
         dwReturn["WDPERFDATN"] = " ".PadRight(8 ); 
         dwReturn["WDPTREND"] = " ".PadRight(0 ); 
         dwReturn["WDPLOSGR"] = " ".PadRight(0 ); 
         dwReturn["WDPBED1"] = " ".PadRight(0 ); 
         dwReturn["WDPBED2"] = " ".PadRight(0 ); 
         dwReturn["WDPBED3"] = " ".PadRight(0 ); 
         dwReturn["WDPBED4"] = " ".PadRight(0 ); 
         dwReturn["WDPBED5"] = " ".PadRight(0 ); 
         dwReturn["WDPBED6"] = " ".PadRight(0 ); 
         dwReturn["WDPBED7"] = " ".PadRight(0 ); 
         dwReturn["WDPBED8"] = " ".PadRight(0 ); 
         dwReturn["WDPBED9"] = " ".PadRight(0 ); 
         dwReturn["WDPBED10"] = " ".PadRight(0 ); 
         dwReturn["WDPBED11"] = " ".PadRight(0 ); 
         dwReturn["WDPBED12"] = " ".PadRight(0 ); 
         dwReturn["WDPWOBEDKZ"] = " ".PadRight(1 ); 
         dwReturn["WDPBEM"] = " ".PadRight(50 ); 
         dwReturn["WDPFILLER"] = " ".PadRight(18 ); 
         dwReturn["WDPAENZL"] = " ".PadRight(0 ); 
         dwReturn["WDPAENB"] = " ".PadRight(8 ); 
         dwReturn["WDPAEND"] = " ".PadRight(0 ); 
         dwReturn["WDPNEUB"] = " ".PadRight(8 ); 
         dwReturn["WDPNEUD"] = " ".PadRight(0 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWDPLAN(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWDPLAN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWDPLAN(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWDPLAN(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWDPLAN(dwLocal, ITXDBVERSION);
            }
            UpdateWDPLAN(dwLocal);
        }
        public void InsertWDPLAN(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WDPLAN(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWDPLAN(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WDPLAN WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WDPLAN  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WDPLAN";
            Return = Result;
            return Return;
        }
        public void DeleteWDPLAN(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WDPLAN   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWDPLAN(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WDPLAN SET "
                    +"WDPMANDANT= :WDPMANDANT,"
                    +"WDPWAKZ= :WDPWAKZ,"
                    +"WDPKUNDNR= :WDPKUNDNR,"
                    +"WDPWERK= :WDPWERK,"
                    +"WDPABT= :WDPABT,"
                    +"WDPDART= :WDPDART,"
                    +"WDPDVAR= :WDPDVAR,"
                    +"WDPDESS= :WDPDESS,"
                    +"WDPCOLORIT= :WDPCOLORIT,"
                    +"WDPFARBE= :WDPFARBE,"
                    +"WDPBESCHICH= :WDPBESCHICH,"
                    +"WDPPROGRP= :WDPPROGRP,"
                    +"WDPARTGRP= :WDPARTGRP,"
                    +"WDPPLMGA= :WDPPLMGA,"
                    +"WDPERFBENA= :WDPERFBENA,"
                    +"WDPERFDATA= :WDPERFDATA,"
                    +"WDPPLMGN= :WDPPLMGN,"
                    +"WDPERFBENN= :WDPERFBENN,"
                    +"WDPERFDATN= :WDPERFDATN,"
                    +"WDPTREND= :WDPTREND,"
                    +"WDPLOSGR= :WDPLOSGR,"
                    +"WDPBED1= :WDPBED1,"
                    +"WDPBED2= :WDPBED2,"
                    +"WDPBED3= :WDPBED3,"
                    +"WDPBED4= :WDPBED4,"
                    +"WDPBED5= :WDPBED5,"
                    +"WDPBED6= :WDPBED6,"
                    +"WDPBED7= :WDPBED7,"
                    +"WDPBED8= :WDPBED8,"
                    +"WDPBED9= :WDPBED9,"
                    +"WDPBED10= :WDPBED10,"
                    +"WDPBED11= :WDPBED11,"
                    +"WDPBED12= :WDPBED12,"
                    +"WDPWOBEDKZ= :WDPWOBEDKZ,"
                    +"WDPBEM= :WDPBEM,"
                    +"WDPFILLER= :WDPFILLER,"
                    +"WDPAENZL= :WDPAENZL,"
                    +"WDPAENB= :WDPAENB,"
                    +"WDPAEND= :WDPAEND,"
                    +"WDPNEUB= :WDPNEUB,"
                    +"WDPNEUD= :WDPNEUD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WDPMANDANT", OracleType.NVarChar).Value = dwData["WDPMANDANT"].ToString(); 
          or1.Parameters.Add("WDPWAKZ", OracleType.NVarChar).Value = dwData["WDPWAKZ"].ToString(); 
          or1.Parameters.Add("WDPKUNDNR", OracleType.NVarChar).Value = dwData["WDPKUNDNR"].ToString(); 
          or1.Parameters.Add("WDPWERK", OracleType.NVarChar).Value = dwData["WDPWERK"].ToString(); 
          or1.Parameters.Add("WDPABT", OracleType.NVarChar).Value = dwData["WDPABT"].ToString(); 
          or1.Parameters.Add("WDPDART", OracleType.NVarChar).Value = dwData["WDPDART"].ToString(); 
          or1.Parameters.Add("WDPDVAR", OracleType.NVarChar).Value = dwData["WDPDVAR"].ToString(); 
          or1.Parameters.Add("WDPDESS", OracleType.NVarChar).Value = dwData["WDPDESS"].ToString(); 
          or1.Parameters.Add("WDPCOLORIT", OracleType.NVarChar).Value = dwData["WDPCOLORIT"].ToString(); 
          or1.Parameters.Add("WDPFARBE", OracleType.NVarChar).Value = dwData["WDPFARBE"].ToString(); 
          or1.Parameters.Add("WDPBESCHICH", OracleType.NVarChar).Value = dwData["WDPBESCHICH"].ToString(); 
          or1.Parameters.Add("WDPPROGRP", OracleType.NVarChar).Value = dwData["WDPPROGRP"].ToString(); 
          or1.Parameters.Add("WDPARTGRP", OracleType.NVarChar).Value = dwData["WDPARTGRP"].ToString(); 
          or1.Parameters.Add("WDPPLMGA", OracleType.NVarChar).Value = dwData["WDPPLMGA"].ToString(); 
          or1.Parameters.Add("WDPERFBENA", OracleType.NVarChar).Value = dwData["WDPERFBENA"].ToString(); 
          or1.Parameters.Add("WDPERFDATA", OracleType.NVarChar).Value = dwData["WDPERFDATA"].ToString(); 
          or1.Parameters.Add("WDPPLMGN", OracleType.NVarChar).Value = dwData["WDPPLMGN"].ToString(); 
          or1.Parameters.Add("WDPERFBENN", OracleType.NVarChar).Value = dwData["WDPERFBENN"].ToString(); 
          or1.Parameters.Add("WDPERFDATN", OracleType.NVarChar).Value = dwData["WDPERFDATN"].ToString(); 
          or1.Parameters.Add("WDPTREND", OracleType.NVarChar).Value = dwData["WDPTREND"].ToString(); 
          or1.Parameters.Add("WDPLOSGR", OracleType.NVarChar).Value = dwData["WDPLOSGR"].ToString(); 
          or1.Parameters.Add("WDPBED1", OracleType.NVarChar).Value = dwData["WDPBED1"].ToString(); 
          or1.Parameters.Add("WDPBED2", OracleType.NVarChar).Value = dwData["WDPBED2"].ToString(); 
          or1.Parameters.Add("WDPBED3", OracleType.NVarChar).Value = dwData["WDPBED3"].ToString(); 
          or1.Parameters.Add("WDPBED4", OracleType.NVarChar).Value = dwData["WDPBED4"].ToString(); 
          or1.Parameters.Add("WDPBED5", OracleType.NVarChar).Value = dwData["WDPBED5"].ToString(); 
          or1.Parameters.Add("WDPBED6", OracleType.NVarChar).Value = dwData["WDPBED6"].ToString(); 
          or1.Parameters.Add("WDPBED7", OracleType.NVarChar).Value = dwData["WDPBED7"].ToString(); 
          or1.Parameters.Add("WDPBED8", OracleType.NVarChar).Value = dwData["WDPBED8"].ToString(); 
          or1.Parameters.Add("WDPBED9", OracleType.NVarChar).Value = dwData["WDPBED9"].ToString(); 
          or1.Parameters.Add("WDPBED10", OracleType.NVarChar).Value = dwData["WDPBED10"].ToString(); 
          or1.Parameters.Add("WDPBED11", OracleType.NVarChar).Value = dwData["WDPBED11"].ToString(); 
          or1.Parameters.Add("WDPBED12", OracleType.NVarChar).Value = dwData["WDPBED12"].ToString(); 
          or1.Parameters.Add("WDPWOBEDKZ", OracleType.NVarChar).Value = dwData["WDPWOBEDKZ"].ToString(); 
          or1.Parameters.Add("WDPBEM", OracleType.NVarChar).Value = dwData["WDPBEM"].ToString(); 
          or1.Parameters.Add("WDPFILLER", OracleType.NVarChar).Value = dwData["WDPFILLER"].ToString(); 
          or1.Parameters.Add("WDPAENZL", OracleType.NVarChar).Value = dwData["WDPAENZL"].ToString(); 
          or1.Parameters.Add("WDPAENB", OracleType.NVarChar).Value = dwData["WDPAENB"].ToString(); 
          or1.Parameters.Add("WDPAEND", OracleType.NVarChar).Value = dwData["WDPAEND"].ToString(); 
          or1.Parameters.Add("WDPNEUB", OracleType.NVarChar).Value = dwData["WDPNEUB"].ToString(); 
          or1.Parameters.Add("WDPNEUD", OracleType.NVarChar).Value = dwData["WDPNEUD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
